const ws=require('ws')

;((ws)=>{
    const server=new ws.Server({port:8000})
    const init=()=>{
      bindEvent()  
    }

    function bindEvent(){
        server.on('open',handleOpen)
        server.on('close',handleClose)
        server.on('error',handleError)
        server.on('connection',handleConnection)
    }
    function handleOpen(){}
    function handleClose(){}
    function handleError(){}
    function handleConnection(ws){
        ws.on('message',handleMessage)
    }

    function handleMessage(msg){
    // let stringmsg=JSON.parse(msg)
    server.clients.forEach(function(c){
        c.send(msg,{binary:false});
       
    }
    )
}

    init()
})(ws)